using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using ebcpatterns.rx;
using NUnit.Framework;

namespace ebcpatterns.tests.rx
{
    [TestFixture]
    public class test_INPCToStream
    {
        [Test]
        public void Several_changes()
        {
            var c = new Changing();

            var sut = new INotifyPropertyChangedToStream();
            c.PropertyChanged += sut.Process;

            var values = new List<StreamedPropertyChangedEventArgs>();
            sut.PropertyChanged += values.Add;

            c.SomeProperty = 42;
            c.SomeProperty = 99;

            Assert.AreEqual(new[] {c, c}, values.Select(_ => _.Sender));
            Assert.AreEqual(new[] { "SomeProperty", "SomeProperty" }, values.Select(_ => _.PropertyName));
        }
    }


    public class Changing : INotifyPropertyChanged
    {
        public int SomeProperty
        {
            set { PropertyChanged(this, new PropertyChangedEventArgs("SomeProperty")); }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}